home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / boot / czesc_2 / smsrc / sm / logfile.pas < prev    next >
Pascal/Delphi Source File  |  1995-07-11  |  2KB  |  91 lines

  1. Type
  2.     tLogData = Record
  3.         ld_fh : BPTR;
  4.     End;
  5.     
  6. Var
  7.     lf : tLogData;
  8.     
  9. Procedure InitLogFile(VAR lf : tLogData; really : Boolean);
  10.  
  11. Const
  12.     LOGNAME : String[9] = 'S:SM_LOG'#0;
  13.     
  14. Var
  15.     Ok  : Boolean;
  16.     pos : LONG;
  17.     
  18. Begin
  19.     lf.ld_fh := NULL;
  20.     { if user wants logfile... }
  21.     If really then begin
  22.         { open file }
  23.         lf.ld_fh := Open(@LOGNAME[1], MODE_READWRITE);
  24.         if lf.ld_fh <> NULL then begin
  25.             { seek to end }
  26.             Pos := Seek_(lf.ld_fh, 0, OFFSET_END);
  27.         End;
  28.     End;
  29. End;
  30.  
  31. Procedure WriteLogFile(lf : tLogData; node : pMyNode; def : Boolean);
  32.  
  33. Const
  34.     { it's documented in the Autodocs but not in the includes }
  35.     FORMAT_DEF = 4;
  36.     
  37. Var
  38.     s, time, 
  39.     date, day : String;
  40.     ds        : tDateStamp;
  41.     pds       : pDateStamp;
  42.     dt        : tDateTime;
  43.     ok        : Boolean;
  44.     err       : LONG;
  45.     
  46. Begin
  47.     { does user want logfile }
  48.     If lf.ld_fh <> NULL then begin
  49.         { command user launched }
  50.         if def then 
  51.             s := 'Default command exit'
  52.         else
  53.             s := node^.LSK_Name;
  54.         { remove any trailing nulls }
  55.         s := s + #0;
  56.         S := PtrToPas(@s[1]);
  57.         { time cmd was launched at }
  58.         pds := @ds;
  59.         pds := DateStamp(pds);
  60.         With dt do begin
  61.             dat_Stamp   := ds;
  62.             dat_Format  := FORMAT_DEF;
  63.             dat_Flags   := 0;
  64.             dat_StrDay  := @day[1];
  65.             dat_StrDate := @date[1];
  66.             dat_StrTime := @time[1];
  67.         End;
  68.         Ok := DateToStr(@dt);
  69.         With dt do
  70.             s := PtrToPas(dat_StrDay) + ' ' + PtrToPas(dat_StrDate) + ' ' + 
  71.                  PtrToPas(dat_StrTime) + ' ' + s + #10 + #0;
  72.         { write the string to the file }
  73.         err := FPuts(lf.ld_fh,@s[1]);
  74.     End;
  75. End;
  76.  
  77. Procedure FreeLogFile(VAR lf : tLogData);
  78.  
  79. Var
  80.     OK : Boolean;
  81.  
  82. Begin
  83.     if lf.ld_fh <> NULL then begin
  84.         Ok := Close_(lf.ld_fh);
  85.         lf.ld_fh := NULL;
  86.     End;
  87. End;
  88.         
  89.         
  90.             
  91.